package com.linux.huhx.codetools.getinfo;

import com.linux.huhx.codetools.constant.Constants;
import com.linux.huhx.codetools.databean.RequestBeanTwo;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by huhx on 2017-06-14.
 */
public class GetinfoFromExcel {
    public static List<RequestBeanTwo> getRequestInfoTwoColumn(String fileName) {
        Workbook wb = null;
        List<RequestBeanTwo> lists = new ArrayList<>();
        try {
            wb = new XSSFWorkbook(new FileInputStream(new File(Constants.PATH_FILE_DIRECTORY, fileName)));
            Sheet sheet = wb.getSheetAt(0);
            int firstRowNum = sheet.getFirstRowNum();
            int lastRowNum = sheet.getLastRowNum();
            for (int i = firstRowNum; i <= lastRowNum; i++) {
                RequestBeanTwo bean = new RequestBeanTwo();
                bean.setComment(sheet.getRow(i).getCell(0).toString());
                bean.setName(sheet.getRow(i).getCell(1).toString());
                lists.add(bean);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                wb.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return lists;
    }
}
